﻿using System;
using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Excel.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NP.BPMReportPlatform.RecurringJobs;
using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.Demo
{
    /// <summary>
    /// Demo 接口
    /// </summary>   
    [ApiController]
    [Route("api/Demo")]
    public class DemoController : BPMReportPlatformController
    {
        private readonly IDemoService _demoService;
        private readonly IPhoneFeeLimitRecurringJob _phoneFeeLimitRecurring;
        private readonly IFlowUrgingRecurringJob _flowUrgingRecurringJob;
        private readonly IFrameOrderRecurringJob _frameOrderRecurringJob;
        private readonly IEngineJob _engineJob;
        private readonly IEmployeeRecurringJob _employeeRecurringJob;

        public DemoController(IDemoService demoService, IPhoneFeeLimitRecurringJob phoneFeeLimitRecurring, IFlowUrgingRecurringJob flowUrgingRecurringJob,
            IFrameOrderRecurringJob frameOrderRecurringJob, IEngineJob engineJob, IEmployeeRecurringJob employeeRecurringJob)
        {
            _demoService = demoService;
            _phoneFeeLimitRecurring = phoneFeeLimitRecurring;
            _flowUrgingRecurringJob = flowUrgingRecurringJob;
            _frameOrderRecurringJob = frameOrderRecurringJob;
            _engineJob = engineJob;
            _employeeRecurringJob = employeeRecurringJob;
        }


        /// <summary>
        /// 自动生成话费额度
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("AutoPhoneFeeLimit")]
        public async Task AutoPhoneFeeLimitAsync()
        {
            await _phoneFeeLimitRecurring.AutoPhoneFeeLimitAsync();
        }

        /// <summary>
        /// 自动生成交通费额度
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("AutoTrafficFeeLimit")]
        public async Task AutoTrafficFeeLimitAsync()
        {
            await _phoneFeeLimitRecurring.AutoTrafficFeeLimitAsync();
        }

        /// <summary>
        /// 定时推送交通费额度到费控
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("PushTrafficFeeLimit")]
        public async Task PushTrafficFeeLimitAsync()
        {
            await _phoneFeeLimitRecurring.PushTrafficFeeLimitAsync();
        }

        /// <summary>
        /// 手动 催办逾期未处理的依赖书流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("AutoFlowUrgingTo1Async")]
        public async Task AutoFlowUrgingTo1Async()
        {
            await _flowUrgingRecurringJob.AutoFlowUrgingTo1Async();
        }

        /// <summary>
        /// 手动推送  框架订单推送数据到移动报销和SAP
        /// </summary>
        /// <param name="instanceNumber">单号</param>
        /// <param name="type">推送类型：1-移动报销，2-SAP</param>
        [HttpGet]
        [Route("SyncFrameOrder")]
        public async Task SyncFrameOrder([FromQuery] string instanceNumber, [FromQuery] string type)
        {
            await _frameOrderRecurringJob.SyncFrameOrder(instanceNumber,type);
        }

        /// <summary>
        /// 手动 催办逾期未处理的流程
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("AutoFlowUrgingOverdueAsync")]
        public async Task AutoFlowUrgingOverdueAsync()
        {
            await _flowUrgingRecurringJob.AutoFlowUrgingOverdueAsync();
        }


        ///// <summary>
        ///// 归档记录表
        ///// </summary>
        ///// <returns></returns>
        //[HttpPost("ArchiveRecordsTable")]
        //public async Task ArchiveRecordsTable()
        //{
        //    await _engineJob.ArchiveRecordsTable();
        //}

        /// <summary>
        /// 从hana同步公司编码与名称到BPM库
        /// </summary>
        /// <returns></returns>
        [HttpGet("SyncCompanyAsync")]
        public async Task SyncCompanyAsync()
        {
            await _employeeRecurringJob.SyncCompanyAsync();
        }

        /// <summary>
        /// 获取岗位代理数据
        /// </summary>
        /// <returns></returns>
        [HttpGet("SyncPostRelationAsync")]
        public async Task SyncPostRelationAsync()
        {
            await _employeeRecurringJob.SyncPostRelationAsync();
        }
    }
}
